import java.math.BigDecimal;
import java.util.Random;

/**
 * 电脑对象：
 *      属性：
 *          winCount 记录电脑赢了几局
 *          playCount 总局数
 *          fit 拳
 *      行为：
 *          showFit() 出拳
 *          calculate() 计算胜率
 */
public class Computer {

    public int winCount;

    public int playCount;

    String fit;

    /**
     * 出拳的方法
     * @return
     */
    public String showFit(){
        Random random = new Random();
        int ran = random.nextInt(3)+1;

        switch (ran){
            case 1:
                fit = "石头";
                break;
            case 2:
                fit = "剪刀";
                break;
            case 3:
                fit = "布";
                break;
        }
        return fit;
    }

    public void calculate(int playerWinCount){

        if(playCount != 0){

            BigDecimal playerBig = new BigDecimal(playerWinCount);
            BigDecimal countBig = new BigDecimal(playCount);

            BigDecimal rate = playerBig.divide(countBig,2,BigDecimal.ROUND_HALF_DOWN);

            System.out.println("您的胜率为："+rate.toString());
        }else{
            System.out.println("您还未开始就结束了...");
        }

    }
}
